package httpServer;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * Simple UI class, used to display when a client connects and how many have connected 
 * @author Li Weihan, Scott Wendlandt, and Rebecca Chandler
 *
 */
public class ServerUI {
	// UI frame
	JFrame frame = new JFrame("Server Status window");
	// The count of connections
	private int count=0;
	// The number of JLables in the frame
	private int item=0;
	
	/**
	 * Initialize the GUI components
	 */
	public ServerUI(){
		frame.setSize(300, 300);
		frame.setLocation(300,300);
		frame.setTitle("Web Server");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLayout(new GridLayout(7,1));
		frame.add(new JLabel("Server Launched."));
		frame.setVisible(true);
		count++;
	}
	
	/**
	 * Update the status when called by the server
	 * @param status string of the update information
	 */
	public void addStatus(String status){
		JLabel newStatus = new JLabel (status + " #" + count);
		if(count>4){
			frame.getContentPane().remove(0);
			item--;
		}
		frame.add(newStatus);
		frame.setVisible(true);
		count++;
		item++;
	}
}
